// 一个数如果恰好等于它的因子之和，这个数就称为"完数"。例如6=1＋2＋3.编程找出1000以内的所有完数
#include <stdio.h>
#include <string.h>
void cal_this(int num, int *buf, int size)
{
    memset(buf,0,size);
    buf[0] = 1;
    buf++;
    for(int i = 2; i <= (num/2); i++)
    {
        if(num%i == 0)
        {
            buf[0] = i;
            buf++;
        }
        else
        {
            continue;
        }
    }
    return;
}
int is_this(int num, int *buf)
{
    int acc = 0;
    int i = 0;
    while(buf[i])
    {
        acc += buf[i];
        i++;
    }
    if(num == acc)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main(int argc, char *argv[])
{
    int buf[100] = {0};
    int n = sizeof(buf);
    for(int i = 1; i < 1000; i++)
    {
        cal_this(i, buf, n);
        if(is_this(i, buf))
        {
            printf("%d\n", i);
        }
        else
        {
            continue;
        }
    }
    return 0;
}